package com.bluesky.comm;

public class ResultUtils {
    public static final String SUCCESS = "1";
    public static final String FAIL = "0";

    public static <T> Result<T> success() {
        return result(true,SUCCESS,null, null);
    }

    public static <T> Result<T> success(T data) {
        return result(true,SUCCESS,data, null);
    }

    public static <T> Result<T> success(T data,String msg) {
        return result(true,SUCCESS,data, msg);
    }

    public static <T> Result<T> fail(String msg) {
        return result(true,FAIL,null, msg);
    }

    public static <T> Result<T> error(String code,String msg) {
        return result(false,code,null, msg);
    }

    public static <T> Result<T> error(String msg){
        return result(false,ErrorCode.SERVER_ERROR,null, msg);
    }

    public static <T> Result<T> result(Boolean success,String code,T data,String msg) {
        Result<T> r = new Result<>();
        r.setSuccess(success);
        r.setCode(code);
        r.setData(data);
        r.setMsg(msg);
        return r;
    }
}
